<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
<%@page import="com.pengtu.gsj.entity.app.User"%>
<%@page import="com.pengtu.gsj.security.SpringSecurityUtils"%>
<!DOCTYPE html>
<html>
<head>
<title>修改密码</title>
<script type="text/javascript" src="${ctxStatic}/CryptoJS/components/core-min.js" charset="utf-8" ></script>
<script type="text/javascript" src="${ctxStatic}/CryptoJS/rollups/sha256.js" charset="utf-8" ></script>
<script type="text/javascript" src="${ctx}/js/password.js" charset="utf-8" ></script>
<link href="${ctx}/styles/css/password.css" type="text/css" rel="stylesheet" />
<script type="text/javascript">
		$(document).ready(function() {
			$("#oldPassword").focus();
			$("#inputForm").validate({
				rules: {
					newPassword:{
						loginPdcode:true,
						remote:"${ctx}/user/checkNewPassword.do",
					},
					oldPassword:{
						loginPdcode:true,
						remote:"${ctx}/user/checkOldPassword.do",
					}
				},
				messages: {
					confirmNewPdcode: {equalTo: "输入与上面相同的密码"},
					oldPassword:{
						remote:"原始密码错误"
					},
					newPassword:{
						remote:"不能和原始密码一样"
					}
				},
				submitHandler: function(form){
					loading("修改密码中...");
					var username=$('#username').val();
					var oldPassword=$('#oldPassword').val(); 
					var newPassword=$('#newPassword').val(); 
					oldPassword= CryptoJS.SHA256(oldPassword+"{"+username+"}");
					newPassword= CryptoJS.SHA256(newPassword+"{"+username+"}");
					$('#oldPassword').val(oldPassword);
					$('#newPassword').val(newPassword);
					$('#confirmNewPdcode').val(newPassword);
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs" style="margin:0 4px;">
		<li><a href="${ctx}/user/view.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}">
			<i class="icon icon-list"></i>&nbsp;<span>个人信息</span></a></li>
		<li class="active"><a href="${ctx}/user/changePw.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}">
		     <i class="icon icon-edit"></i>&nbsp;<span>修改密码</span></a></li>
	</ul>
	<form id="inputForm" action="${ctx}/user/updatePwd.do?top=${fns:encodeParam(top)}&left=${fns:encodeParam(left)}" 
		method="post" class="form-horizontal propertyHeight" style="overflow:auto;margin-top:10px;">
		<input type="hidden" name="token" value="${token}">
		<input type="hidden" name="id" value="${user.id}">
		<tags:message content="${msg}"/>
		<div class="control-group">
			<label class=" control-label">旧密码<font style="color:red;">*</font>:</label>
			<div class="controls">
				<input id="oldPassword" name="oldPassword" type="password" value="" class="required"/>
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">新密码<font style="color:red;">*</font>:</label>
			<div class="controls">
				<input id="newPassword" name="newPassword" type="password" value=""  class="required"/>
				<br/>
				<br/>
				<span>(密码必须包含大写字母、小写字母、数字,长度在6~12位之间,不能与旧密码相同)</span>
				<div id="level" class="pw-strength">
					<div class="pw-bar"></div>
					<div class="pw-bar-on"></div>
					<div class="pw-txt">
						<span>弱</span>
						<span>中</span>
						<span>强</span>
					</div>
				</div>
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">确认新密码<font style="color:red;">*</font>:</label>
			<div class="controls">
				<input id="confirmNewPdcode" name="confirmNewPdcode" type="password" value="" class="required" equalTo="#newPassword"/>
			</div>
		</div>
		<input type="hidden" id="username" name="username" value="<%=((User)SpringSecurityUtils.getCurrentUser()).getUsername()%>">
		<div class="form-actions">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>
		</div>
	</form>
</body>
</html>